var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {
	  //inline scripts related to this page
	jQuery(function($) {

		var basePath = "/" + app.contextPath;
		//var basePath = "/" + app.mvcContextPath;

		// 搜索项配置
		var searchOption = [
			{id:'id',title:'序号',type:"text"},
			{id:'Domain',title:'域名',field:'Domain',type:"text",className:"input-small",value:'',placeholder:"域名",disabled:false,readonly:false},
			{id:'date',title:'日期',type:"datetime",format:"YYYY-MM-DD"},
			{id:'datetime',title:'时间',type:"datetime",format:"YYYY-MM-DD HH:mm:ss"},
			{id:'time',title:'时刻',type:"datetime",format:"hh:mm:ss"},
			{id:'sex',title:'性别',type:"select",value:'',placeholder:"请选择...",fieldKey:"sex",fieldValue:"sexName",data:[{sex:1,sexName:"男"},{sex:2,sexName:"女"}]},
			{id:'sexId',title:'性别',type:"select",value:'',data:{"1":"男","2":"女"}},
			{id:'DomainId',title:'域名',type:"select",value:"",multiple:false,fieldKey:"id",fieldValue:"Domain",data:basePath + "/resources/assets/data/grid.json",dataParam:{},dataSrc:"result"},
			{}
		];
		// dataTables配置
		var dataTablesOption = {
			language: {
				url: basePath + "/resources/assets/data/grid-cn.json",
			},
			ajax: {
				"url": basePath + "/resources/assets/data/grid.json",
			},
			columns: [
				{
					data: "id",
					title: "序号",
					orderData: [ 0, 1 ],
				},{
					data: "Domain",
					title: "域名",
					render: function ( data, type, row, meta ) {
						return '<a href="#">' + row.Domain + '</a>';
					}
				},{
					data: "Price",
					title: "价格",
					render: function ( data, type, row, meta ) {
						return '$' + data;
					}
				},{
					data: "Clicks",
					title: "点击数",
					className: "hidden-480",
				},{
					data: "Update",
					title: "更新时间",
				},{
					data: "Status",
					title: "状态",
				},{
					data: "id",
					title: "",
					orderable: false,
					render: function ( data, type, row, meta ) {
						return '<div class="btn-group dropup">' +
									'<button data-toggle="dropdown" class="btn btn-primary btn-white dropdown-toggle">' +
										'操作' +
										'<i class="ace-icon fa fa-angle-down icon-on-right"></i>' +
									'</button>' +
									'<ul class="dropdown-menu dropdown-info dropdown-menu-right">' +
										'<li>' +
											'<a class="blue" href="javascript:;" onclick="changeAjaxContent(\'#page/tables?id=' + row.id + '\')" >' +
												'<i class="ace-icon fa fa-search-plus bigger-130"></i>' +
												'查看明细' +
											'</a>' +
										'</li>' +
									'</ul>' +
								'</div>';
					}
				}
			],
			select: {
				// 选择方式，单行：single，多行：multi
				style: 'single',
			},
		};
		var gridSettings = {
			// 主键字段
			pkField : "id",
			// ID前缀
			prefixId : "dynamic",
			// 是否为树形结构
			isTreeGrid : 1,
			// 搜索项配置
			searchOption: searchOption,
			// dataTables配置
			dataTablesOption: dataTablesOption,
			// 新增按钮
			addButton: {
				enable: true,
				url: "/Tables/add_edit",
			},
			// 修改按钮
			editButton: {
				enable: true,
				url: "/Tables/add_edit",
			},
			// 永久删除按钮
			deleteButton: {
				enable: true,
				url: basePath + "/resources/assets/data/grid-insert.json",
			},
			// 导出按钮
			exportButton: {
				enable: false,
				url: "",
			},
			// 导入按钮
			importButton: {
				enable: true,
				fieldName: "file",
				url: basePath + "/resources/assets/data/grid-import.json",
			},
			// 查询按钮
			searchButton: {
				enable: true,
			},
		};
	
		var _myTable = $('#dynamicTable').grid(gridSettings);
		var myTable = _myTable.data('grid').objGrid;
		//console.log(_myTable.data('grid'));
		//console.log(myTable);
		
		// 自定义按钮举例
		$("#btnZiDingYi").on('click', function(){
			// 获取选中行数据
			var rows = myTable.rows({selected: true}), datas = rows.data();
			//console.log(rows);
			//console.log(datas);
			// 列表刷新
			myTable.ajax.reload();
		});
	
	})
});

